package edu.nwpu.utils;


import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

public abstract class ResponseUtil {

    public static Map<String, Object> responseOperation(boolean status) {
        Map<String, Object> response = new HashMap<>();
        response.put("status", status ? "success" : "failed");
        return response;
    }

    public static <T> Map<String, Object> responseQueryList(List<T> list) {
        Map<String, Object> response = new HashMap<>();
        if (list == null || list.size() == 0) {
            response.put("status", "failed");
        } else {
            response.put("status", "success");
            response.put("count", list.size());
            response.put("data", list);
        }
        return response;
    }

    public static Map<String, Object> responseQueryOne(Object object) {
        Map<String, Object> response = new HashMap<>();
        if (object == null) {
            response.put("status", "failed");
        } else {
            response.put("status", "success");
            response.put("info", object);
        }
        return response;
    }
}
